import type { Diagram, SetupLocationItem, PartialDiagram, AddProjectMembersParam, ProjectPermission } from "./models";
import req, { RequsetOptons } from "/@/api/req";

export enum Api {
  getLocationList = "api/v1/projects/settings/locations/list",

  getScada = "api/v1/projects/settings/scadas/get",
  getScadaList = "api/v1/projects/settings/scadas/page",
  createScada = "api/v1/projects/settings/scadas/create",
  deleteScada = "api/v1/projects/settings/scadas/delete",
  editScada = "api/v1/projects/settings/scadas/edit",

  getDiagram = "api/v1/projects/settings/diagrams/get",
  updateDiagramBg = "api/v1/projects/settings/diagrams/background_update",
  updateDiagramEq = "api/v1/projects/settings/diagrams/equipment_update",

  getProjectRoles = "api/aiot/projectRoles/getProjectRoles",
  addProjectRoles = "api/aiot/projectRoles/addProjectRoles",
  updateProjectRoleById = "api/aiot/projectRoles/updateProjectRoleById",
  deleteProjectRoleById = "api/aiot/projectRoles/deleteProjectRoleById",
  getProjectPermissions = "api/aiot/projectRoles/getProjectPermissions",

  addProjectMembers = "api/aiot/projectMembers/addProjectMembers",
  listMembersByProjectId = "api/aiot/projectMembers/listMembersByProjectId",
  removeProjectMembersByIds = "api/aiot/projectMembers/removeProjectMembersByIds",
  existProjectMember = "api/aiot/projectMembers/existProjectMember",
}

export function getLocationList(projectId: string) {
  return req.commonPost<SetupLocationItem[]>(Api.getLocationList, { projectId }, { useGlobalLoading: false });
}

export function createScada(data: PartialDiagram) {
  return req.commonPost<Diagram>(Api.createScada, data, { useGlobalLoading: false });
}

export function deleteScada(projectScadaId: string) {
  return req.commonPost<Diagram>(Api.deleteScada, { projectScadaId }, { useGlobalLoading: false });
}

export function editScada(data: PartialDiagram) {
  return req.commonPost<boolean>(Api.editScada, data, { useGlobalLoading: false });
}

export function getDiagram(data: PartialDiagram) {
  return req.commonPost<Diagram>(Api.getDiagram, data, { useGlobalLoading: true, useLog: false });
}

export function updateDiagramBg(data: PartialDiagram) {
  return req.commonPost<Diagram>(Api.updateDiagramBg, data, { useGlobalLoading: false });
}

export function updateDiagramEq(data: PartialDiagram) {
  return req.commonPost<Diagram>(Api.updateDiagramEq, data, { useGlobalLoading: true });
}

export function addProjectMembers(data: AddProjectMembersParam) {
  return req.commonPost<boolean>(Api.addProjectMembers, data, { useGlobalLoading: false, useCustomFailMes: false });
}

export function existProjectMember(data: { phone: string; projectId: string }) {
  return req.commonPost<boolean>(Api.existProjectMember, data, { useGlobalLoading: false });
}

export function getProjectPermissions(projectId: string, options: RequsetOptons) {
  return req.commonPost<ProjectPermission>(Api.getProjectPermissions, { projectId }, options);
}
